(function(global, document, _fns, $, console) {
  'use strict';

  /*
  
      @name 自动嵌套命名空间
  
      @desc
  
      @author
  
      @access protected
  
      @function _extend
  
      @param {Object} ns 顶级命名空间
  
      @param {string} [nsString = tlns.ns1.ns2.ns3] 基于顶级命名空间要嵌套的命名空间
  
      @returns {Object} 返回嵌套好的对象。
  
      @example
          // " tlns.sample = $.noop; " === " tlns.ns1.ns2.ns3.sample = $.noop; "
          var tlns = _extend(tlns, "tlns.ns1.ns2.ns3");
  
      @todo 将这个函数放入公共函数库中。
   */
  var _extend, exc;
  _extend = function(ns, nsString) {
    var i, parent, parts, pl;
    parts = nsString.split(".");
    parent = ns;
    pl = parts.length;
    i = 0;
    while (i < pl) {
      if (typeof parent[parts[i]] === "undefined") {
        parent[parts[i]] = {};
      }
      parent = parent[parts[i]];
      i++;
    }
    return parent;
  };
  exc = _extend(_fns, "_fns.excute");

  /*
      @desc
  
      @author
  
      @access protected
  
      @function exc._fast_click
   */
  exc.sidebar = function() {
    global.lsBar();
  };

  /*
      @desc
  
      @author
  
      @access protected
  
      @function exc.rating
   */
  exc.rating = function() {
	  
    var fnRating, rating, rates, fnTransferData, btnSubmit, successForwardUrl;
    rates = $('#ratingData').attr('data-rating');
    
    rating = $('.starrr');
    btnSubmit = $('.btnSubmit');
    successForwardUrl = '/member/myEvaluation.htm';
    
    rating.starrr({
      emptyStarClass: 'icon-star-empty',
      fullStarClass: 'icon-star'
    });
    fnRating = function(e, value) {
    	rates = value;
    };
    
    rating.on('starrr:change', fnRating);
    
    fnTransferData = function (url, data) {
    	
    	var transfer;
    	
    	transfer = $.ajax(url, {
    		data: data,
    		type: "POST"
    	});
    	
    	transfer.done(function (data, textStatus, jqXHR) {
    		ECar.easyDialog.open({
 				container : {
 					header : '提示',
 					content : '<div style="text-align:center">评价成功</div>'
 				},
 				callback: location.href = successForwardUrl
 			});
    	});
    	
    	transfer.fail(function (jqXHR, textStatus, errorThrown) {
    		ECar.easyDialog.open({
 				container : {
 					header : '提示',
 					content : '<div style="text-align:center">评价失败</div>'
 				}
 			});
    	});
    	
    };
    
    btnSubmit.on('click', function (e) {
    	
    	e.stopPropagation();
    	e.preventDefault();
    	
    	var _objectId, _content, _iptAnonymity, content;
    	
    	_objectId = $('input[name="objectId"]').val();
    	_content = $('textarea[name="content"]').val().replace(/\n/g,"@@@@");
    	_iptAnonymity = $('input[name="iptAnonymity"]').is(':checked');
    	
    	if ($.trim(_content) !== '') {
    		fnTransferData('/member/saveEvaluation.htm', {
        		objectId: _objectId,
        		score: rates,
        		content: _content,
        		iptAnonymity: _iptAnonymity
        	});
    	} else {
    		 ECar.easyDialog.open({
 				container : {
 					header : '提示',
 					content : '<div style="text-align:center">请输入评价内容</div>'
 				}
 			});
    	}
    	
    });
    
  };

  /*
      @name 初始化
  
      @desc 所有在 " _fns.excute " 命名空间下定义的函数将被自动运行。
  
      @author
  
      @access protected
  
      @function _fns.init
  
      @param {Object} opts 存放定义好的可任意修改（配置）的行为选项。
   */
  _fns.init = function(opts) {
    var _it;
    for (_it in exc) {
      if (typeof exc[_it] === "function") {
        exc[_it]();
      }
    }
  };
  $(_fns.init);
})(window, document, {}, jQuery, (typeof console !== 'undefined' ? console : void 0));
